coos.event = function(e)
{
	var e = e || window.event;
	return e;
};

coos.event.format = function(e) 
{
	var e = e || window.event;
	try
	{
		if(!e.pageX && e.clientX)//firefox3 nonsupport pageX
		{
			e.pageX = e.clientX + document.body.scrollLeft;
			e.pageY = e.clientY + document.documentElement.scrollTop;
		}
	}
	catch(e){}
	
	if(window.event)
	{
		e.charCode = (e.type == "keypress") ? e.keyCode : 0;
		e.eventPhase = 2;
		e.isChar = (e.charCode > 0);
		e.preventDefault = function ()
		{
			this.returnValue = false;
		};
		
		if(e.type == "mouseout")
		{
			e.relatedTarget = e.toElement;
		}
		else if(e.type == "mouseover")
		{
			e.relatedTarget = e.formElement;
		}
		
		e.stopPropagation = function ()
		{
			this.cancelBubble = true;
		};
		
		e.target = e.srcElement;
		e.time   = (new Date()).getTime();
	}
	
	try
	{
		if (e.target.nodeType == 3)
		{// defeat Safari bug
			e.target = e.target.parentNode;
		}
		//如果不存在keyCode属性，同时存在which属性则赋值,因为该属性为只读属性(has only a getter)
		if(!e.keyCode && e.which)
		{
			e.keyCode = e.which;
		}
	}
	catch(e){}
	
	return e;
};

coos.event.add = function(el,EventType,callback)
{
	var obj = coos.$obj(el);
	
	if(obj.addEventListener)
	{
		obj.addEventListener(EventType,callback,false);
	}
	else if(obj.attachEvent)
	{
		obj.attachEvent('on'+EventType,callback);
	} 
	else
	{
		obj['on'+EventType] = callback;
	}
};

coos.event.remove = function(el,EventType,callback)
{
	var obj = coos.$obj(el);
	
	if(obj.removeEventListener)
	{
		obj.removeEventListener(EventType,callback,false);
	} 
	else if(obj.detachEvent)
	{
		obj.detachEvent('on'+EventType,callback);
	} 
	else
	{
		obj['on'+EventType] = callback;
	}
};

coos.event.stop = function(e) 
{
    coos.event.format(e).stopPropagation();
};

coos.event.cancel = function(e) 
{
    coos.event.format(e).preventDefault();
};

coos.event.pageX = function(e)
{
	return coos.event.format(e).pageX;
};

coos.event.pageY = function(e)
{
	return coos.event.format(e).pageY;
};

coos.event.element = function(e)
{
	return coos.event.format(e).target;
};

coos.event.keyCode = function(e)
{
	return coos.event.format(e).keyCode;	
};